/**
 * 获取浏览器参数
 */
export const getParams = key => {
    var href = window.location.href.replace(/&#38;/g,"&");
  　var reg = new RegExp("(^|\\?|&)"+ key +"=([^&]*)(\\s|&|$)", "i");
　　if (reg.test(href))
　　return unescape(RegExp.$2.replace(/\+/g, " "));
　　return "";
}

/**
 * 固定列后滚动条滚动bug处理
 */
export const devScroll = (obj) =>{
  //console.log(obj);
  if(obj.length == 0){
    return;
  }
  var boxwrp = obj[0]; 
  var box = document.getElementById('box'); 
  //兼容firefox 
  if(boxwrp.addEventListener){ 
    document.addEventListener("DOMMouseScroll", fn, false); 
  } 
  document.onmousewheel = fn;//兼容IE、chrome 
    
  function fn(ev){ 
    var ev = ev||event; 
    var bool = false; 
    var scrollh = 0;
    //IE、chrome 向上：120，向下：-120 
    //console.log(ev);
    if(ev.wheelDelta){ 
      bool= ev.wheelDelta > 0? true : false; 
    } 
    //firefox 向上：-3，向下：3 
    else{ 
      bool= ev.detail < 0? true : false; 
    } 
    scrollh = bool ? -40 : 40;
    obj.scrollTop(obj.scrollTop()+scrollh);
  } 
}

/**
 * 分页返回数据处理
 */
export const getPageData = (data) =>{
  if(data){
    for(var i=0,l=data.length;i<l;i++){
  　　for(var key in data[i]){
          data[i][key] = <span className="tdspan" dangerouslySetInnerHTML={{__html:data[i][key]}}></span>;
  　　}
    }
    return data;
  }
  return [];
}

/**
 * 千分位转化
 */
export const comdify = (num) => {
    var reg=/\d{1,3}(?=(\d{3})+$)/g;   
    return (num + '').replace(reg, '$&,');  
}

/**
 * 初始化页面实际高度
 */
export const initHeight = (_this) => {
    let header = document.getElementsByClassName("e9theme-layout-header")[0];
    if(header){
      _this.setState({height: this.getHeight(header)});
    }
}

export const getHeight = (header) => {
    let h = 0;
    if (header) {
        h = header.clientHeight || 0;
    }
    return window.innerHeight - h;
}